﻿@using reCAPTCHA.AspNetCore
@using reCAPTCHA.AspNetCore.Versions;
@using Microsoft.Extensions.Options

@model ContactModel
@inject IOptions<RecaptchaSettings> RecaptchaSettings;

@{
    ViewData["Title"] = "Contact";
}
<!--
    This example shows how to use a hidden button to delay recatpcha processing in a form.
    You can modify OnPost to validate form input using whatever library you wish
-->
<h2>@ViewData["Title"]</h2>
<h3>@ViewData["Message"]</h3>

<address>
    One Microsoft Way<br />
    Redmond, WA 98052-6399<br />
    <abbr title="Phone">P:</abbr>
    425.555.0100
</address>

<address>
    <strong>Support:</strong> <a href="mailto:Support@example.com">Support@example.com</a><br />
    <strong>Marketing:</strong> <a href="mailto:Marketing@example.com">Marketing@example.com</a>
</address>

@using (Html.BeginForm("Contact", "Home", FormMethod.Post))
{
    @Html.ValidationSummary(true)
<fieldset>
    <div class="form-group">
        @Html.LabelFor(model => model.Message)
        <br />
        @Html.TextAreaFor(model => model.Message, new { @class = "form-control", rows = "3", style = "width: 300px;" })
    </div>
    <div class="form-group">
        @(Html.Recaptcha<RecaptchaV2Invisible>(RecaptchaSettings.Value))
    </div>
    <button id="submit" type="submit" class="btn btn-primary" onclick="OnPost()">Submit</button>
    <button id="recaptcha" type="button" class="btn btn-primary" style="visibility: hidden;">Recaptcha</button>
</fieldset>
}

<script>
    function OnPost() {
        alert('Using OnPost');
        document.getElementById('recaptcha').click();
    }
</script>